package com.gzp.queue.listener;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

/**
 * 队列的生产者，使用监听器接收。只要向被监听的目的地发送消息，便会立马被监听器监听到，无需启动消费者。
 * 
 * @author Administrator
 *
 */
public class TestQueueProducerListener {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application-queue-listener.xml");
		JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
		jmsTemplate.send(new MessageCreator() {

			@Override
			public Message createMessage(Session session) throws JMSException {
				TextMessage textMessage = session.createTextMessage("mq-spring-queue");
				return textMessage;
			}
		});
		System.out.println("消息发送完成！");
	}
}
